package com.loopy.tomcat.utils;

import java.io.BufferedReader;
import java.io.FileReader;

public class WebUtils {
    public static int parseInt(String num,int defaultval){
        try {
            return Integer.parseInt(num);
        } catch (NumberFormatException e) {
            System.out.println(num+"格式错误");
        }
         return defaultval;
    }

    public  static boolean isHtml(String uri){
        return uri.endsWith(".html");
    }

    public static String readHtml(String fileName){
//        System.out.println("读取.html文件");
        String path = WebUtils.class.getResource("/").getPath();
//        System.out.println("path="+path);
        StringBuilder builder=new StringBuilder();
        try {
            BufferedReader br = new BufferedReader(new FileReader(path + fileName));
//            System.out.println("文件地址是"+(path + fileName));
            String buf="";
            while ((buf=br.readLine())!=null){
                builder.append(buf);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return builder.toString();
    }
}
